package ClientSim;

import server.Out;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.*;
import java.net.Socket;
import java.util.Date;

public class Main {
    public static void main(String[] args) throws Exception {
        Socket socket=new Socket("127.0.0.1",5400);

        JFrame wd=new JFrame();
        wd.setSize(200,200);
        wd.setLocation(200,200);
        wd.setAlwaysOnTop(true);
        JButton rush=new JButton("rush");
        wd.add(rush);
        rush.addActionListener((ActionEvent e)->{
            try {
                BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                bw.write("rush "+(new Date().getTime()));
                bw.newLine();
                bw.flush();
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
        });
        wd.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        wd.setVisible(true);
        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(socket.getInputStream()));
//        String s=bufferedReader.readLine();
//        Out.say("server reply:"+s);
        BufferedWriter bufferedWriter=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        bufferedWriter.write("id "+(new Date().getTime())%100000/1000);
        bufferedWriter.newLine();
        bufferedWriter.flush();
//        bufferedWriter=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
//        bufferedWriter.write("time");
//        bufferedWriter.newLine();
//        bufferedWriter.flush();

        Out.say("server reply:"+bufferedReader.readLine());
        //Out.say("server reply:"+bufferedReader.readLine());
        //Out.say("server reply:"+bufferedReader.readLine());
        //Out.say("server reply:"+bufferedReader.readLine());
        //new Thread().sleep(1000);
    }
}
